home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: pointers
- Date: 25 Feb 1996 21:08:51 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb25140851@qcd.lanl.gov>
- References: <4gqh8g$bo4@news.bu.edu>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: lachesis@cs.bu.edu's message of 25 Feb 1996 20:36:32 GMT
-
- In article <4gqh8g$bo4@news.bu.edu>
- lachesis@cs.bu.edu (wai yip) writes:
-
- wy: can someone who knows a lot about pointers help me with this
-
- I never claim to know a lot about anything. I will try to help you
- anyway. However, remember asking questions in a newsgroup is no
- alternative to actually studying a language. I will suggest you read a
- good C text book, the FAQ can guide you with examples of good books.
-
- wy:
- wy: int i=3,*p;
- wy:
- wy: with the above declaration, what would the bottom lines do?
- wy: *p=&i;
-
- Compilation error. &i is a pointer to int, *p is an int. A pointer to
- int cannot be converted to an int without a cast. With a cast, whether
- it is allowed is upto the implementation (which must document it). It
- leads to undefined behaviour in addition, see the third case below.
-
- Note that compilation error means that the compiler is required to
- give a diagnostic of some sort. What it does after giving the
- diagnostic is upto it.
-
- wy: p=i;
-
- Compilation error. p is a pointer to an int, i is an int. An int
- cannot be assigned to a pointer without a cast.
-
- wy: *p=i;
-
- Undefined behaviour (which means virtually anything can happen, with
- or without compiler diagnostic). *p tries to dereference p which has
- not been assigned yet.
-
- If p has been assigned a valid pointer to an object, this will set
- that object to the current value of i, which is 3.
-
- wy: p=&i;
-
- It assigns the address of i to p. After this, unless p is changed, *p
- refers to the object i.
-
- wy:
- wy: please answer me through email because i don't usually read newsgroups.
-
- Sorry.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-